package LeetCode.leetcode46;

import java.util.ArrayList;
import java.util.List;

public class Review1 {
    public List<List<Integer>> permute(int[] nums) {
        List<List<Integer>> ans = new ArrayList<>();
        backtrack(nums, ans, new ArrayList<>());
        return ans;
    }
    public void backtrack(int[] nums, List<List<Integer>> ans, List<Integer> levelAns) {
        if (nums.length == levelAns.size()) {
            ans.add(new  ArrayList<>(levelAns));
            return;
        }
        for (int i = 0; i < nums.length; i++) {
            if (levelAns.contains(nums[i])) continue;
            levelAns.add(nums[i]);
            backtrack(nums, ans, levelAns);
            levelAns.remove(levelAns.size() - 1);
        }
    }
}
